package org.xdj.blue.java.aio.server;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

public class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, AysnSocketServer> {


	public void completed(AsynchronousSocketChannel result,
			AysnSocketServer attachment) {
		System.out.println("--AcceptCompletionHandler线程名："+Thread.currentThread().getName()+"--");
		//再次获取客服端请求
		attachment.asynServerSocketChannel.accept(attachment, this);
		
		ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
		result.read(byteBuffer, byteBuffer, new ReadCompletionHandler(result));
	}

	public void failed(Throwable exc, AysnSocketServer attachment) {
		attachment.latch.countDown();
	}

}
